package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */

    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id主键查询
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    Orders getById(Integer id);

    @Select("select * from orders where id=#{id}")
    Orders getByIds(Long id);

    @Select("select count(id) from orders where status=#{status}")
    Integer countStatus(Integer status);

    /**
     * 根据状态和时间获取订单
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
//    @Select("SELECT * FROM orders WHERE status=#{status} AND order_time < DATE_SUB(#{orderTime}, INTERVAL 15 MINUTE)")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

//    @Select("select sum(amount) from orders where order_time>#{beginTime} and order_time<#{endTime} and status=5")
//    Long getByDate(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 根据map进行封装,获取每日营业额
     * @param map
     * @return
     */
    Double sumByMap(Map map);


    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 统计指定时间区间内销量排名前10
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
